#include "commandlineedit.h"
//
CommandLineEdit::CommandLineEdit(QWidget *parent=0) 
	: QLineEdit()
{
	setParent(parent);
	setText("Type your Command");
	count=0;
	CLEH.clear();
	CLEH.append("Type your Command");
	CLEH.append("");
	
	upArrow=new QShortcut(this);
	upArrow->setKey(Qt::Key_Up);
	connect(this->upArrow,SIGNAL(activated()),this,SLOT(backInHistory()));
	
	downArrow=new QShortcut(this);
	downArrow->setKey(Qt::Key_Down);
	connect(this->downArrow,SIGNAL(activated()),this,SLOT(forwardInHistory()));
	
	enter=new QShortcut(this);
	enter->setKey(Qt::Key_Return);
	connect(this->enter,SIGNAL(activated()),this,SLOT(validateCommand()));
}

CommandLineEdit::~CommandLineEdit(){
	delete upArrow;
	delete downArrow;
	delete enter;
}

void CommandLineEdit::backInHistory(){
	if(count>0){
		count--;
		this->setText(CLEH.at(count));
	}
}

void CommandLineEdit::forwardInHistory(){
	if(count<(CLEH.size()-1)){
		count++;
		this->setText(CLEH.at(count));
	}
}

void CommandLineEdit::validateCommand(){
	CLEH.removeLast();
	CLEH.append(this->displayText());
	CLEH.append("");
	count=CLEH.size()-1;
	emit customReturnPressed();
}

//
